guint lower_sensitive : 1;
guint upper_sensitive : 1;
+ /* The range has an origin, should be drawn differently. Used by GtkScale */
+ guint has_origin : 1;
+
/* Fill level */
guint show_fill_level : 1;
guint restrict_to_fill_level : 1;
priv->upper_sensitivity = GTK_SENSITIVITY_AUTO;
priv->lower_sensitive = TRUE;
priv->upper_sensitive = TRUE;
+ priv->has_origin = FALSE;
priv->show_fill_level = FALSE;
priv->restrict_to_fill_level = TRUE;
priv->fill_level = G_MAXDOUBLE;
if (draw_trough)
{
- gint trough_change_pos_x = width;
- gint trough_change_pos_y = height;
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- trough_change_pos_x = (priv->slider.x +
- priv->slider.width / 2 -
- x);
- else
- trough_change_pos_y = (priv->slider.y +
- priv->slider.height / 2 -
- y);
-
- /* FIXME: was trough-upper and trough-lower really used,
- * in that case, it should still be exposed somehow.
- */
- gtk_render_background (context, cr, x, y,
- trough_change_pos_x,
- trough_change_pos_y);
+ if (!priv->has_origin)
+ {
+ gtk_render_background (context, cr,
+ x, y, width, height);
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- trough_change_pos_y = 0;
+ gtk_render_frame (context, cr,
+ x, y, width, height);
+ }
else
- trough_change_pos_x = 0;
-
- gtk_render_background (context, cr,
- x + trough_change_pos_x, y + trough_change_pos_y,
- width - trough_change_pos_x,
- height - trough_change_pos_y);
-
- gtk_render_frame (context, cr,
- x, y, width, height);
+ {
+ gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
+
+ gint trough_change_pos_x = width;
+ gint trough_change_pos_y = height;
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ trough_change_pos_x = (priv->slider.x +
+ priv->slider.width / 2 -
+ x);
+ else
+ trough_change_pos_y = (priv->slider.y +
+ priv->slider.height / 2 -
+ y);
+
+ gtk_style_context_save (context);
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+
+ if (!is_rtl)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
+ }
+ else
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
+
+ gtk_render_background (context, cr, x, y,
+ trough_change_pos_x,
+ trough_change_pos_y);
+
+ gtk_render_frame (context, cr, x, y,
+ trough_change_pos_x,
+ trough_change_pos_y);
+
+ gtk_style_context_restore (context);
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ trough_change_pos_y = 0;
+ else
+ trough_change_pos_x = 0;
+
+ gtk_style_context_save (context);
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+
+ if (is_rtl)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
+ }
+ else
+ {
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
+ }
+
+ gtk_render_background (context, cr,
+ x + trough_change_pos_x, y + trough_change_pos_y,
+ width - trough_change_pos_x,
+ height - trough_change_pos_y);
+
+ gtk_render_frame (context, cr,
+ x + trough_change_pos_x, y + trough_change_pos_y,
+ width - trough_change_pos_x,
+ height - trough_change_pos_y);
+
+ gtk_style_context_restore (context);
+ }
}
else
{
}
}
+void
+_gtk_range_set_has_origin (GtkRange *range,
+ gboolean has_origin)
+{
+ range->priv->has_origin = has_origin;
+}
+
+gboolean
+_gtk_range_get_has_origin (GtkRange *range)
+{
+ return range->priv->has_origin;
+}
+
void
_gtk_range_set_stop_values (GtkRange *range,
gdouble *values,
PROP_0,
PROP_DIGITS,
PROP_DRAW_VALUE,
+ PROP_HAS_ORIGIN,
PROP_VALUE_POS
};
P_("Whether the current value is displayed as a string next to the slider"),
TRUE,
GTK_PARAM_READWRITE));
-
+
+ g_object_class_install_property (gobject_class,
+ PROP_HAS_ORIGIN,
+ g_param_spec_boolean ("has-origin",
+ P_("Has Origin"),
+ P_("Whether the scale has an origin"),
+ TRUE,
+ GTK_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class,
PROP_VALUE_POS,
g_param_spec_enum ("value-pos",
gtk_range_set_slider_size_fixed (range, TRUE);
+ _gtk_range_set_has_origin (range, TRUE);
+
priv->draw_value = TRUE;
priv->value_pos = GTK_POS_TOP;
priv->digits = 1;
case PROP_DRAW_VALUE:
gtk_scale_set_draw_value (scale, g_value_get_boolean (value));
break;
+ case PROP_HAS_ORIGIN:
+ gtk_scale_set_has_origin (scale, g_value_get_boolean (value));
+ break;
case PROP_VALUE_POS:
gtk_scale_set_value_pos (scale, g_value_get_enum (value));
break;
case PROP_DRAW_VALUE:
g_value_set_boolean (value, priv->draw_value);
break;
+ case PROP_HAS_ORIGIN:
+ g_value_set_boolean (value, gtk_scale_get_has_origin (scale));
+ break;
case PROP_VALUE_POS:
g_value_set_enum (value, priv->value_pos);
break;
return scale->priv->draw_value;
}
+/**
+ * gtk_scale_set_has_origin:
+ * @scale: a #GtkScale
+ * @has_origin: %TRUE if the scale has an origin
+ *
+ * If @has_origin is set to %TRUE (the default),
+ * the scale will highlight the part of the scale
+ * between the origin (bottom or left side) of the scale
+ * and the current value.
+ *
+ * Since: 3.4
+ */
+void
+gtk_scale_set_has_origin (GtkScale *scale,
+ gboolean has_origin)
+{
+ GtkScalePrivate *priv;
+
+ g_return_if_fail (GTK_IS_SCALE (scale));
+
+ priv = scale->priv;
+
+ has_origin = has_origin != FALSE;
+
+ if (_gtk_range_get_has_origin (GTK_RANGE (scale)) != has_origin)
+ {
+ _gtk_range_set_has_origin (GTK_RANGE (scale), has_origin);
+
+ gtk_widget_queue_draw (GTK_WIDGET (scale));
+
+ g_object_notify (G_OBJECT (scale), "has-origin");
+ }
+}
+
+/**
+ * gtk_scale_get_has_origin:
+ * @scale: a #GtkScale
+ *
+ * Returns whether the scale has an origin.
+ *
+ * Returns: %TRUE if the scale has an origin.
+ *
+ * Since: 3.4
+ */
+gboolean
+gtk_scale_get_has_origin (GtkScale *scale)
+{
+ g_return_val_if_fail (GTK_IS_SCALE (scale), FALSE);
+
+ return _gtk_range_get_has_origin (GTK_RANGE (scale));
+}
+
/**
* gtk_scale_set_value_pos:
* @scale: a #GtkScale